package com.createidea.scrumfriend.service.project;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import com.createidea.scrumfriend.dao.project.ProjectDao;
import com.createidea.scrumfriend.dao.user.UserDao;
import com.createidea.scrumfriend.to.ProjectTo;
import com.createidea.scrumfriend.to.UserTo;

public class ProjectServiceImpl implements ProjectService {

	private ProjectDao projectDao;
	private UserDao userDao;

	public ProjectDao getProjectDao() {
		return projectDao;
	}

	public void setProjectDao(ProjectDao projectDao) {
		this.projectDao = projectDao;
	}

	@Override
	public void createProject(ProjectTo project) {
		// TODO Auto-generated method stub
		Set users=project.getUsers();
		users.add(project.getUser());
		project.setUsers(users);
		projectDao.saveProject(project);
	}

	@Override
	public List<ProjectTo> getProjectsForUser(String userId) {
		// TODO Auto-generated method stub
		List<ProjectTo> projectList = null;
		UserTo user = userDao.getUserById(userId);
		if (user != null) {
			Set<ProjectTo> projects = userDao.getUserById(userId).getProjects();
			if (projects != null && projects.size() > 0)
				projectList = new ArrayList<ProjectTo>(projects);
		}
		return projectList;
	}

	@Override
	public void deleteProject(ProjectTo project) {
		projectDao.deleteProject(project);
	}

	@Override
	public ProjectTo getProjectById(String id) {
		
		return projectDao.getProjectById(id);
	}

	@Override
	public void updateProject(ProjectTo projectTo) {
		Set users=projectTo.getUsers();
		users.add(projectTo.getUser());
		projectTo.setUsers(users);
		projectDao.updateProject(projectTo);
		
	}

	public UserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	
	  
	  
}
